var ajax = require('./ajax.js');


function Pagination(options) {
	this.options = options;
	this.page = 1;

	this._getPage();
}

Pagination.prototype = {

	_getPage() {
		var _self = this;
		var options = _self.options;
		var params = options.params;

		params.page = _self.page;

		options.beforeGetPage && options.beforeGetPage(_self.page);

		ajax.G(options.url, params, function(d) {

			options.getPageSuccess && options.getPageSuccess(_self.page, d);

		});

	},

	loadNext() {
		this.page++;
		this._getPage();
	},

	flush() {
		this.page = 1;
		this._getPage();
	}


};

module.exports = Pagination;